{% extends base.html %}

{% block head %}

<link rel="stylesheet" href="/static/lib/codemirror/codemirror.min.css">
<link rel="stylesheet" type="text/css" href="/static/lib/codemirror/theme/monokai.min.css">
<link rel="stylesheet" type="text/css" href="/static/lib/codemirror/theme/xq-light.css">
<script type="text/javascript" src="/static/lib/codemirror/codemirror.min.js"></script>
<script type="text/javascript" src="/static/js/editor.js"></script>
<script type="text/javascript" src="/static/lib/codemirror/mode/clike/clike.js"></script>
<script type="text/javascript" src="/static/lib/codemirror/mode/shell.js"></script>
<script type="text/javascript" src="/static/lib/codemirror/mode/python.js"></script>
<script type="text/javascript" src="/static/lib/codemirror/mode/javascript.js"></script>
<script type="text/javascript" src="/static/lib/codemirror/mode/markdown.js"></script>

{% if path.endswith(".php") %}
<script type="text/javascript" src="/static/lib/codemirror/mode/php.js"></script>
{% end %}

<style type="text/css">
    .search-key {
        background-color: #FF8000;
        color: #000;
    }

    #result {
        border: 1px solid #ccc;
        padding: 4px;
        background-color: #9cc;
        box-sizing: border-box;
    }
</style>
{% end %}

{% block body %}
{% init pathlist = [] %}

<div class="fs-path">
    <a href="/fs//">Home</a> /
    {% for item in pathlist %}
        <a href="/fs/{{ item.path }}">{{ item.name }}</a> / 
    {% end %}
</div>

<div class="col-md-12">
    <p style="color:red">{{?error}}</p>
</div>
<textarea id="content" class="hide">{{content}}</textarea>
<form method="POST" action="/code/view_source/update">
<div class="col-md-12">
    <input name="path" class="hide" value="{{path}}"/>
    <div id="editorArea" class="col-md-12">
        <textarea name="content" id="editor">{{content}}</textarea>
    </div>

    <div class="col-md-12 bottom-offset-1">
        <input type="submit" value="保存">
        <input id="execute" type="button" class="btn hide" value="执行"/>
        {% if path.endswith(".md") %}
            <input type="button" class="link-btn" href="/code/preview?path={{path}}" value="预览">
        {% end %}
    </div>

    <div id="resultDiv" class="col-md-12 hide">
        结果
        <pre id="result" class="col-md-12">
        </pre>
    </div>
</div>
</form>

{# TODO 需要处理下搜索的高亮 #}

<script type="text/javascript">
    $(function () {
        var editor = initCodeMirror("#editor", {
            filename: getUrlParams().path,
            height: "500px"
        })
        window.codeMirror = editor;
    });
</script>
{% end %}